package xgenerator.ui.swing;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class MetadataTableCellRenderer extends DefaultTableCellRenderer {

//	public static final Color SELECTION_BACKGROUND_COLOR = new Color(233, 242, 241);
	public static final Color SELECTION_BACKGROUND_COLOR = new Color(207, 228, 249);
	public static final Color EVEN_ROW_COLOR = new Color(229, 255, 228);
//	public static final Color EVEN_ROW_COLOR = new Color(233, 242, 241);
	public static final Color ODD_ROW_COLOR = new Color(255, 255, 255);
	
	/**
	 * <p>
	 * Title：
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @param table
	 * @param value
	 * @param isSelected
	 * @param hasFocus
	 * @param row
	 * @param column
	 * @return
	 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
	 */
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		
		this.setColor(cell, table, value, isSelected, hasFocus, row, column);
//		return cell;
		return this;
	}
	
	/**
	 * <p>
	 * Title：
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @param cell
	 * @param table
	 * @param value
	 * @param isSelected
	 * @param hasFocus
	 * @param row
	 * @param column
	 */
	private void setColor(Component cell, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if(isSelected) {
			cell.setBackground(SELECTION_BACKGROUND_COLOR);
			table.setBorder(null);
		} else {
			if(row % 2 == 0) {
				cell.setBackground(EVEN_ROW_COLOR);
			} else {
				cell.setBackground(ODD_ROW_COLOR);
			}
		}
		
		
	}
	
}
